Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现了对用户空间传入指针抽象的UserBufferReader/Writer,来检验用户空间指针地址并提供一定的功能抽象 #326

Merged
merged 15 commits into from
Aug 21, 2023

Conversation

Chiichen
Copy link
Member

No description provided.

/// @return 构造成功返回UserbufferReader实例,否则返回错误码
///
pub fn new(addr: *const T, len: usize) -> Result<Self, SystemError> {
if unsafe { !verify_area(addr as u64, (len * core::mem::size_of::<T>()) as u64) } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个verify area不要使用C的,rust版本之前有写过,参考syscall/syscall.rs


#[derive(Debug)]
pub struct UserBufferReader<T> {
addr: *const T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以直接存储数组的引用,这样能够更安全。
现在这样,直接存裸指针的话,后面每次读取,都手动转数组引用。实际上是在一定程度上绕过了借用检查

然后我感觉从通用性考虑,这里完全可以转为&[u8]

在读取函数那里,可以允许通过任意的类型来解析它。这样会更好。

@fslongjin fslongjin merged commit 4537ffb into DragonOS-Community:master Aug 21, 2023
1 check passed
@Chiichen Chiichen deleted the userbuffer-dev branch August 21, 2023 16:53
@Chiichen Chiichen restored the userbuffer-dev branch August 21, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants